13주차 - 파노라마 영상¶


▶ 이미지 스티칭¶

  • 사진 이어 붙이기, 파노라마 영상(panorama image)
  • 방법
    • 여러장의 영상에서 특징점을 검출
    • 동일한 특징점 찾기(매칭)
    • 투시변환을 이용하여 붙이기(영상 결합)
    • 노출 보정, 블렌딩을 적용
      image.png
      image-2.png
      image-3.png
      image-4.png

▶ OpenCV¶

  • Images stitching
    • https://docs.opencv.org/4.x/d1/d46/group__stitching.html

image.png

  • Stitcher Class Reference
    • cv2.Stitcher_create() -> retval
    • cv.Stitcher.stitch(images) -> retval, pano
      • images: Input images.
In [ ]:
### Packages
import sys
import os
import numpy as np
import cv2
In [ ]:
### change the current working directory
os.chdir(r'D:\image')
In [ ]:
### 입력 영상 이름
img_names = ['hnu_20220530_01.jpg', 'hnu_20220530_02.jpg']

### 영상 저장
imgs = []
for name in img_names:
    img = cv2.imread(name)

    if img is None:
        print('Image load failed!')
        sys.exit()

    imgs.append(img)

### 이미지 스티칭
stitcher = cv2.Stitcher_create()
status,dst = stitcher.stitch(imgs)

if status != cv2.Stitcher_OK:
    print('Stitch failed!')
    sys.exit()

### 파노라마 영상 저장
cv2.imwrite('output.jpg',dst)
In [ ]:
### 파노라마 영상 출력
cv2.namedWindow('dst',cv2.WINDOW_NORMAL)
cv2.imshow('dst',dst)
cv2.waitKey()
cv2.destroyAllWindows()

hnu_20220530_01.jpg

hnu_20220530_02.jpg

output.jpg